/*路由统一入口*/

"use strict";

var express = require("express");
var routerList = require("./routerList");
var router = express.Router();
var {
  verifyFun
} = require("../middleware/verify");
var {
  globalCode
} = require("../config/globalCode");

router.all("*", function (req, res, next) {
  //设置响应头
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Content-Type");
  res.header("Access-Control-Allow-Methods", "*");
  res.header("Content-Type", "application/json;charset=utf-8");

  //设置响应超时时间(15s)
  res.setTimeout(15 * 1000, function () {
    return res.send(globalCode.M_REQUEST_TIMEOUT);
  });

  //路由入口统一的鉴权方法举例（或者其他验证方法）
  verifyFun(req, res).then(resIn => {
    if (resIn === true) {
      next();
    }
    else {
      res.send(resIn);
    }
  })
});


module.exports = [router, ...routerList];